package com.hspedu.collection_;

import java.util.HashSet;
import java.util.Objects;
@SuppressWarnings({"all"})
public class HashSetEx01 {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        Employ1 jack = new Employ1("jack", 3000, new MyData(2000, 10, 24));
        Employ1 merry = new Employ1("merry", 4000, new MyData(2021, 6, 17));
        Employ1 merry1 = new Employ1("merry", 4000, new MyData(2021, 6, 17));
        Employ1 jack1 = new Employ1("jack", 3000, new MyData(2000, 10, 24));
        Employ1 jack2 = new Employ1("jack", 3000, new MyData(2000, 10, 24));
        hashSet.add(jack);
        hashSet.add(merry);
        hashSet.add(jack1);
        hashSet.add(jack2);
        System.out.println(hashSet);
    }
}

class Employ1{
    private String name;
    private int sal;
    private MyData myData;



    public Employ1(String name, int sal, MyData myData) {
        this.name = name;
        this.sal = sal;
        this.myData = myData;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSal() {
        return sal;
    }

    public void setSal(int sal) {
        this.sal = sal;
    }

    public MyData getMyData() {
        return myData;
    }

    public void setMyData(MyData myData) {
        this.myData = myData;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employ1 employ1 = (Employ1) o;
        return sal == employ1.sal && this.name.equals(employ1.getName()) && this.myData.equals(employ1.getMyData());
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sal, myData);
    }

    @Override
    public String toString() {
        return "Employ1{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", myData=" + myData +
                '}';
    }
}






class MyData{
    private int year;
    private int month;
    private int day;

    public MyData(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyData myData = (MyData) o;
        return year == myData.year && month == myData.month && day == myData.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }

    @Override
    public String toString() {
        return "MyData{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
}
